package com.authService.controller;

import com.authService.pojo.req.PermissionEditReqDTO;
import com.authService.pojo.req.PermissionPageReqDTO;
import com.authService.pojo.res.PermissionDetailResDTO;
import com.authService.pojo.res.PermissionPageResDTO;
import com.authService.service.ISysPermissionService;
import com.xiaopeng.common.httpResult.model.HttpResult;

import com.xiaopeng.common.page.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统权限表 前端控制器
 * </p>
 *
 * @author xiaopeng
 * @since 2024-09-22
 */
@Tag(name = "系统权限")
@RestController
@RequestMapping("/permission")
public class SysPermissionController {

    @Resource
    private ISysPermissionService sysPermissionService;

    @Operation(summary = "系统权限-分页查询")
    @PostMapping("/page")
    public HttpResult<PageVO<PermissionPageResDTO>> selectPage(@RequestBody PermissionPageReqDTO reqDTO) {
        return HttpResult.success(sysPermissionService.selectPage(reqDTO));
    }


    @Operation(summary = "系统权限-详情")
    @GetMapping("/detail")
    public HttpResult<PermissionDetailResDTO> detail(@RequestParam Long permissionId) {
        return HttpResult.success(sysPermissionService.detail(permissionId));
    }

    @Operation(summary = "系统权限-保存")
    @PostMapping("/save")
    public HttpResult<Void> save(@RequestBody @Valid PermissionEditReqDTO reqDTO) {
        sysPermissionService.savePermission(reqDTO);
        return HttpResult.success();
    }

    @Operation(summary = "系统权限-修改")
    @PostMapping("/update")
    public HttpResult<Void> update(@RequestBody @Valid PermissionEditReqDTO reqDTO) {
        sysPermissionService.updatePermission(reqDTO);
        return HttpResult.success();
    }

    @Operation(summary = "系统权限-删除")
    @GetMapping("/delete")
    public HttpResult<Void> delete(@RequestParam Long permissionId) {
        sysPermissionService.delete(permissionId);
        return HttpResult.success();
    }

}
